<%@ page contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="dbexp.model.Table"%>
<%@page import="dbexp.model.Column"%>
<%@page import="dbexp.model.db.DbUser"%>
<%@page import="dbexp.connection.DbMetaData"%>
<%@page import="org.json.JSONArray"%>
<%@page import="org.json.JSONObject"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%
DbUser u = (DbUser)session.getAttribute("USER");
String name = request.getParameter("name");
String schema = request.getParameter("schema");
boolean nowy = (name==null || name.trim().equals("null")) && (schema==null || schema.trim().equals("null"));
Table t = null;
if(!nowy){
	t = DbMetaData.getTable(u, name.toUpperCase(), schema.toUpperCase());
	List<Column> columns = t.getColumns();
		JSONArray data = new JSONArray();
	for (int i = 0; i < columns.size(); i++) {
		Column o = columns.get(i);
		JSONObject json = new JSONObject();
		json.put("name", o.getName());
		json.put("dataType", o.getDataType());
		json.put("size", o.getSize());
		json.put("scale", o.getScale());
		json.put("nullable", o.isNullable());
		json.put("default", o.getDefault());
		data.put(json);
	}
out.clearBuffer();%><%=new JSONObject().
																			put("success", true).
																			put("data",data)%>
<%}
%>